package com.starlinkdt.api.controller.admin.system;

import com.starlinkdt.common.annotation.Log;
import com.starlinkdt.common.core.controller.BaseController;
import com.starlinkdt.common.core.page.TableDataInfo;
import com.starlinkdt.common.domain.AjaxResult;
import com.starlinkdt.common.domain.system.dto.OaiAccDto;
import com.starlinkdt.common.domain.system.entity.OaiAcc;
import com.starlinkdt.common.enums.BusinessType;
import com.starlinkdt.common.utils.poi.ExcelUtil;
import com.starlinkdt.service.system.IOaiAccService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * OAI账户Controller
 *
 * @author system
 */
@Api(tags = "OAI账户管理")
@RestController
@RequestMapping("/admin/openapi/account")
public class OaiAccController extends BaseController {
    @Autowired
    private IOaiAccService oaiAccService;

    /**
     * 查询OAI账户列表
     */
    @ApiOperation("OAI账户-列表")
    @PreAuthorize("@ss.hasPermi('openapi:account:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaiAcc oaiAcc) {
        startPage();
        List<OaiAcc> list = oaiAccService.selectOaiAccList(oaiAcc);
        return getDataTable(list);
    }

    /**
     * 导出OAI账户列表
     */
    @ApiOperation("OAI账户-导出")
    @PreAuthorize("@ss.hasPermi('openapi:account:export')")
    @Log(title = "OAI账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaiAcc oaiAcc) {
        List<OaiAcc> list = oaiAccService.selectOaiAccList(oaiAcc);
        ExcelUtil<OaiAcc> util = new ExcelUtil<OaiAcc>(OaiAcc.class);
        util.exportExcel(response, list, "OAI账户数据");
    }

    /**
     * 获取OAI账户详细信息
     */
    @ApiOperation("OAI账户-查询")
    @PreAuthorize("@ss.hasPermi('openapi:account:query')")
    @GetMapping(value = "/{accBizNo}")
    public AjaxResult getInfo(@PathVariable("accBizNo") String accBizNo) {
        return success(oaiAccService.selectOaiAccByAccBizNo(accBizNo));
    }

    /**
     * 新增OAI账户
     */
    @ApiOperation("OAI账户-新增")
    @PreAuthorize("@ss.hasPermi('openapi:account:add')")
    @Log(title = "OAI账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated({OaiAccDto.Add.class}) OaiAccDto oaiAccDto) {
        return toAjax(oaiAccService.insertOaiAcc(oaiAccDto));
    }

    /**
     * 修改OAI账户
     */
    @ApiOperation("OAI账户-修改")
    @PreAuthorize("@ss.hasPermi('openapi:account:edit')")
    @Log(title = "OAI账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated({OaiAccDto.Edit.class}) OaiAccDto oaiAccDto) {
        return toAjax(oaiAccService.updateOaiAccByAccBizNo(oaiAccDto));
    }

    /**
     * 启用OAI账户
     */
    @ApiOperation("OAI账户-启用")
    @PreAuthorize("@ss.hasPermi('openapi:account:edit')")
    @Log(title = "OAI账户", businessType = BusinessType.UPDATE)
    @PutMapping("enable/{accBizNos}")
    public AjaxResult enable(@PathVariable String[] accBizNos) {
        return toAjax(oaiAccService.enableOaiAccByAccBizNos(accBizNos));
    }

    /**
     * 禁用OAI账户
     */
    @ApiOperation("OAI账户-禁用")
    @PreAuthorize("@ss.hasPermi('openapi:account:edit')")
    @Log(title = "OAI账户", businessType = BusinessType.UPDATE)
    @PutMapping("disable/{accBizNos}")
    public AjaxResult disable(@PathVariable String[] accBizNos) {
        return toAjax(oaiAccService.disableOaiAccByAccBizNos(accBizNos));
    }

    /**
     * 删除OAI账户
     */
    @ApiOperation("OAI账户-删除")
    @PreAuthorize("@ss.hasPermi('openapi:account:remove')")
    @Log(title = "OAI账户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{accBizNos}")
    public AjaxResult remove(@PathVariable String[] accBizNos) {
        return toAjax(oaiAccService.deleteOaiAccByAccBizNos(accBizNos));
    }

}
